<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>登录页面</title>
</head>
<body>
    <div style="text-align: center;">
        <h1>登录</h1>
        ⽤户：<input id="username">
        <br>
        密码：<input id="password" type="password">
        <br>
        <input type="button" value=" 提交 " onclick="mysub()" style="margin-top: 20px;margin-left: 50px;">
    </div>

    <script src="js/jquery.js"></script>
    <script>
        function mysub() {
            let username = jQuery("#username");
            let password = jQuery("#password");
            // 判断输入框是否为空或者只有空格
            if(jQuery.trim(username.val())=="") {
                alert("请先输入用户名!");
                username.focus(); // 光标重置到次元素
                return;
            }
            if(jQuery.trim(password.val())=="") {
                alert("请先输入密码!");
                username.focus(); // 光标重置到次元素
                return;
            }
            jQuery.ajax({
                url: "user/login2",
                type: "post",
                contentType: "application/json",
                data: JSON.stringify({"username":username.val(), "password":password.val()}),
                success: function(body) {
                    alert(JSON.stringify(body));
                    // if(body != null && body.success == 200) {
                    //     if(body.data == 1) {
                    //         // 登录成功
                    //         alert("登录成功!");
                    //     }else {
                    //         alert("登录失败!，账号或密码错误");
                    //     }
                    // }else {
                    //     alert("")
                    // }
                }
            });
        }
    </script>
</body>
</html>